package com.syy.reducejoin;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class OrderJoin implements WritableComparable<OrderJoin> {
    private String oid;
    private String pid;
    private Integer count;
    private String pName;

    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getpName() {
        return pName;
    }

    public void setpName(String pName) {
        this.pName = pName;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(oid);
        dataOutput.writeUTF(pid);
        dataOutput.writeInt(count);
        dataOutput.writeUTF(pName);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.oid = dataInput.readUTF();
        this.pid = dataInput.readUTF();
        this.count = dataInput.readInt();
        this.pName = dataInput.readUTF();
    }

    @Override
    public String toString() {
        return oid + "\t" + pid + "\t" + count + "\t" + pName;
    }

    /**
     * 01  小米
     * 1001 01 1
     * 1004 01 4
     *
     * 02  华为
     * 1002 02 2
     * 1005 02 5
     *
     *
     * 03 格力
     * 1003 03 3
     * 1006 03 6
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(OrderJoin o) {
        // 如果pid一样，按照名字降序
        if(this.pid.equals(o.pid)){
            return o.pName.compareTo(this.pName);//
        }else{
            return Integer.compare(Integer.parseInt(this.pid), Integer.parseInt(o.getPid()));
        }    }
}
